using System;
using NUnit.Framework;
using ValidationFramework.Configuration;
using ValidationFramework.Extensions;
using ValidationFramework.Reflection;

namespace ValidationFramework.Tests.Configuration
{
    [TestFixture]
    public class RequiredRuleConfigReaderTest
    {
        #region Methods

        [Test]
        public void ReadConfig()
        {
            const string validatorXml = "<rule errorMessage='hello' initialValue='10' typeName='RequiredRule' ruleSet='foo' />";
            var ruleData = (RuleData.Read(validatorXml.ToXmlReader())); ;
			var rule = (RequiredRule<int>)ConfigurationService.GetRule(ruleData, TypePointers.IntTypeHandle);
            Assert.AreEqual("hello", rule.ErrorMessage);
            Assert.AreEqual(10, rule.InitialValue);


        }

        [Test]
        public void ReadConfigSimple()
        {
            const string validatorXml = "<rule typeName='RequiredRule'/>";
            var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
			var rule = (RequiredRule<int>)ConfigurationService.GetRule(ruleData, TypePointers.IntTypeHandle);


        }
        [Test]
        public void ReadConfigNullable()
        {
            const string validatorXml = "<rule typeName='RequiredRule'/>";
            var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
            var rule = (RequiredRule<int>)ConfigurationService.GetRule(ruleData, typeof(int?).TypeHandle);


        }

        [Test]
        public void ReadConfigDateTime()
        {
            const string validatorXml = "<rule errorMessage='hello' initialValue='10 Mar 2007' typeName='RequiredRule' ruleSet='foo' />";
            var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
            var rule = (RequiredRule<DateTime>)ConfigurationService.GetRule(ruleData, typeof(DateTime).TypeHandle);
            Assert.AreEqual("hello", rule.ErrorMessage);
            Assert.AreEqual(new DateTime(2007,3,10), rule.InitialValue);


        }

        [Test]
        public void ReadConfigDateTimeSimple()
        {
            const string validatorXml = "<rule typeName='RequiredRule'/>";
            var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
            var rule = (RequiredRule<DateTime>)ConfigurationService.GetRule(ruleData, typeof(DateTime).TypeHandle);


        }
        [Test]
        public void ReadConfigDateTimeNullable()
        {
            const string validatorXml = "<rule typeName='RequiredRule'/>";
            var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
            var rule = (RequiredRule<DateTime>)ConfigurationService.GetRule(ruleData, typeof(DateTime?).TypeHandle);


        }

        #endregion


    }
}